﻿using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using AnimationPage.ViewModels;
using AnimationPage.Views;
using Avalonia.Controls;

namespace AnimationPage;

public partial class App : Application
{
    public override void Initialize()
    {
        AvaloniaXamlLoader.Load(this);
    }

    private static MainWindowViewModel _windowViewModel;

    public static void GoPage(UserControl page)
    {
        _windowViewModel.CurrentPage = page;
    }

    public override void OnFrameworkInitializationCompleted()
    {
        if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
        {
            // Line below is needed to remove Avalonia data validation.
            // Without this line you will get duplicate validations from both Avalonia and CT
            BindingPlugins.DataValidators.RemoveAt(0);
            desktop.MainWindow = new MainWindow();

            desktop.MainWindow.DataContext = _windowViewModel = new MainWindowViewModel();
        }

        base.OnFrameworkInitializationCompleted();
    }
}